package com.d3works.apps.base.web;

import com.d3works.apps.base.service.DMSImportWizardService;
import com.d3works.exception.D3worksException;
import com.d3works.meta.db.MetaFile;
import com.d3works.meta.db.repo.MetaFileRepository;
import com.d3works.rpc.ActionRequest;
import com.d3works.rpc.ActionResponse;
import com.google.inject.Inject;
import java.util.Map;

public class DmsImportWizardController {

  @Inject private MetaFileRepository metaFileRepo;

  @Inject DMSImportWizardService dmsImportWizardService;

  public void importDMS(ActionRequest request, ActionResponse response) throws D3worksException {
    try {
      @SuppressWarnings("unchecked")
      Map<String, Object> metaFileMap = (Map<String, Object>) request.getContext().get("metaFile");
      MetaFile metaFile = metaFileRepo.find(Long.parseLong(metaFileMap.get("id").toString()));
      dmsImportWizardService.importDMS(metaFile);
      response.setReload(true);
    } catch (D3worksException e) {
      response.setInfo(e.getMessage());
    }
  }
}
